package com.tinysoft.gameframework;


import com.example.gamedevtest.R;

import android.content.Context;
import android.content.res.AssetManager;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;

public class SoundEffect {

	private SoundPool soundEffectPool;
	
	static public int SOUND_POP;
	
	private float leftVolume;
	private float rightVolume;
	private int priority;
	private int loop;
	private float rate;

	private MediaPlayer backgroundMusic;

	public SoundEffect(Context context) {
		// music
		backgroundMusic = MediaPlayer.create(context, R.raw.gun_battle_sound);
		// sound
		soundEffectPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
		leftVolume = 1;
		rightVolume = 1;
		rate = 1;
		// load sound resource
		SOUND_POP = soundEffectPool.load(context, R.raw.pop_clip_in, 1);
	}
	
	public void playSoundEffect(int effectID) {
		priority = 0;
		loop = 0;
		soundEffectPool.play(effectID, leftVolume, rightVolume, priority, loop, rate);
	}
	
	public void playBackgroundMusic() {
		backgroundMusic.start();
		backgroundMusic.setLooping(true);
	}
	
	public void muteBackgroundMusic() {
		if (backgroundMusic.isPlaying() == true)
			backgroundMusic.pause();
	}
	
	public void stopBackgroundMusic() {
		backgroundMusic.stop();
	}
}
